package com.admin.web.controller;

import com.bayss.core.constant.ResultMsg;
import com.bayss.core.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户操作
 *
 * @author yangjian
 */
@RestController
public class UserController extends ApiBaseController {

    private final UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    /**
     * 查询用户列表
     * userType:1-正常用户；2-充值用户
     */
    @RequestMapping("/user/get_list.json")
    public ResultMsg updateDeliverymanInfo(@RequestParam(name = "page", required = false, defaultValue = "1") Integer page,
                                           @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                           @RequestParam(name = "start", required = false, defaultValue = "0") Long start,
                                           @RequestParam(name = "end", required = false, defaultValue = "0") Long end,
                                           @RequestParam(name = "birStart", required = false, defaultValue = "0") Long birStart,
                                           @RequestParam(name = "birEnd", required = false, defaultValue = "0") Long birEnd,
                                           @RequestParam(name = "cellphone", required = false, defaultValue = "") String cellphone,
                                           @RequestParam(name = "gender", required = false, defaultValue = "-1") Integer gender,
                                           @RequestParam(name = "userType", required = false, defaultValue = "-1") Integer userType) {
        return ResultMsg.success(userService.getUsers(page, pageSize, start, end, birStart, birEnd, gender, cellphone, userType));
    }

    /**
     * 是否能到付
     */
    @RequestMapping("/user/to_pay.json")
    public ResultMsg toPay(@RequestParam(name = "id") Long id,
                           @RequestParam(name = "toPay", required = false, defaultValue = "2") Integer toPay) {
        return ResultMsg.success(userService.updateToPay(id, toPay));
    }

}
